package cn.iocoder.yudao.module.fengdong.smartelderly.controller.app.oldmanpointrecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.oldmanpointrecord.vo.*;
import cn.iocoder.yudao.module.fengdong.smartelderly.convert.oldmanpointrecord.OldmanPointRecordConvert;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.oldmanpointrecord.OldmanPointRecordDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.service.oldmanpointrecord.OldmanPointRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 老人积分记录")
@RestController
@RequestMapping("/fengdong.smartelderly/oldman-point-record")
@Validated
public class AppOldmanPointRecordController {

    @Resource
    private OldmanPointRecordService oldmanPointRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建老人积分记录")
    public CommonResult<Long> createOldmanPointRecord(@Valid @RequestBody OMPointRecordCreateReqVO createReqVO) {
        return success(oldmanPointRecordService.createOldmanPointRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新老人积分记录")
    public CommonResult<Boolean> updateOldmanPointRecord(@Valid @RequestBody OMPointRecordUpdateReqVO updateReqVO) {
        oldmanPointRecordService.updateOldmanPointRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除老人积分记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteOldmanPointRecord(@RequestParam("id") Long id) {
        oldmanPointRecordService.deleteOldmanPointRecord(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得老人积分记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<OldmanPointRecordRespVO> getOldmanPointRecord(@RequestParam("id") Long id) {
        OldmanPointRecordDO oldmanPointRecord = oldmanPointRecordService.getOldmanPointRecord(id);
        return success(OldmanPointRecordConvert.INSTANCE.convert(oldmanPointRecord));
    }

    @GetMapping("/list")
    @Operation(summary = "获得老人积分记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<OldmanPointRecordRespVO>> getOldmanPointRecordList(@RequestParam("ids") Collection<Long> ids) {
        List<OldmanPointRecordDO> list = oldmanPointRecordService.getOldmanPointRecordList(ids);
        return success(OldmanPointRecordConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得老人积分记录分页")
    public CommonResult<PageResult<OldmanPointRecordRespVO>> getOldmanPointRecordPage(@Valid OMPointRecordPageReqVO pageVO) {
        PageResult<OldmanPointRecordDO> pageResult = oldmanPointRecordService.getOldmanPointRecordPage(pageVO);
        return success(OldmanPointRecordConvert.INSTANCE.convertPage(pageResult));
    }

}
